import pygame
import math

# 初始化 Pygame
pygame.init()

# 定义颜色
white = (255, 255, 255)
green = (0, 255, 0)
black = (0, 0, 0)

# 定义窗口大小
dis_width = 800
dis_height = 600

# 创建窗口
dis = pygame.display.set_mode((dis_width, dis_height))
pygame.display.set_caption('Stupid Pea')

clock = pygame.time.Clock()

# 定义字体
font = pygame.font.SysFont(None, 75)

def draw_dynamic_text(surface, text, t):
    surface.fill(white)
    # 动态变化的字体大小
    font_size = 75 + int(10 * math.sin(t))
    dynamic_font = pygame.font.SysFont(None, font_size)
    text_surface = dynamic_font.render(text, True, black)
    text_rect = text_surface.get_rect(center=(dis_width // 2, dis_height // 2 - 50))
    surface.blit(text_surface, text_rect)

def draw_stupid_pea(surface, color, t):
    # 绘制圆形部分
    center_x = dis_width // 2
    center_y = dis_height // 2 + 50
    radius = 50 + int(10 * math.sin(t))  # 动态变化的半径
    pygame.draw.circle(surface, color, (center_x, center_y), radius)
    
    # 绘制眼睛
    eye_radius = 5
    eye_offset_x = 15
    eye_offset_y = 10
    pygame.draw.circle(surface, black, (center_x - eye_offset_x, center_y - eye_offset_y), eye_radius)
    pygame.draw.circle(surface, black, (center_x + eye_offset_x, center_y - eye_offset_y), eye_radius)
    
    # 绘制嘴巴
    mouth_width = 30
    mouth_height = 10 + int(5 * math.sin(t))  # 动态变化的嘴巴高度
    pygame.draw.ellipse(surface, black, [center_x - mouth_width // 2, center_y + eye_offset_y, mouth_width, mouth_height])

def gameLoop():
    # 初始化游戏状态
    game_over = False
    t = 0  # 用于控制字符串和符号动态变化的时间变量

    # 游戏主循环
    while not game_over:
        # 处理事件
        for event in pygame.event.get():
            if event.type == pygame.QUIT:  # 如果接收到退出事件，结束游戏
                game_over = True

        # 绘制动态 Stupid Pea 字符串
        draw_dynamic_text(dis, 'stupid pea', t)
        # 绘制动态 Stupid Pea 符号
        draw_stupid_pea(dis, green, t)
        t += 0.1  # 增加时间变量，使字符串和符号动态变化

        # 更新显示
        pygame.display.update()
        clock.tick(30)  # 控制帧率为每秒30帧

    # 退出 Pygame
    pygame.quit()
    quit()

# 启动游戏循环
gameLoop()